#561  for 语法结构和基于数字（range）的循环 

# for x in range(5):
#     print('hello')

#562  基于列表list，元组tuple的循环

# numbers = [3,4,5,8,2]
# #列表，元组，字典，集合，字符串等都可遍历
# for x in numbers:
#     print(x)

#563  跳过单次循环
# for x in [3,4,5,8,9]:
#     if(x % 3 ==0):
#         continue #跳过本次循环后面的语句，马上进入下一轮循环
#     print(x)
#     print(x*5)
#     print(x*x)


#564  马上退出循环
# numbers = [3,4,5,8,9]
# for x in numbers:
#     if(x == 5):
#         break #直接退出循环
#     print(x)
# print('程序结束了……')


#565  嵌套循环  #566  一次性退出嵌套循环
# names = ['yuwen','jixing','liuli']
# is_found = False
# for name in names:
#     if (is_found):
#         break
#     for n in name:
#         if (n == 'i'):
#             is_found = True
#             break
#         print(n)


#567  显示循环的index和值
# scores = [98,23,97,86,64]
# for order, s in enumerate (scores,1):
#     print(order,s)

#568  循环的本质——到底可以基于什么循环
# for s in 'hello':
#     print(s)

#1. interable
#2. inter('hello'):'hello'._iter_(),返回iterator
#3. next(iterator):_next_()方法 

#569  实现自己的可循环类——随机数循环
import random
class randomcount:
    def __iter__(self):
        return self
    def __next__(self):
        r = random.randint(1,10)
        if(r == 9):
            raise StopIteration
        return r
rc = randomcount()
for s in rc:
    print(s)


#570  再看while循环
